# dfs
direct = [[-1, 0], [0, -1], [1, 0], [0, 1]]

area = 0

def dfs(grid, visited, x, y):
    
    global area
    
    for i,j in direct:
        next_x = x+i
        next_y = y+j
        
        if next_x < 0 or next_x >= len(grid[0]) or next_y<0 or next_y>=len(grid):
            continue
        
        if grid[next_y][next_x] == 1 and not visited[next_y][next_x]:
            area += 1
            visited[next_y][next_x] = True
            dfs(grid, visited, next_x, next_y)
        
def main():  

    row, col = map(int, input().split())
    
    grid = []
    for i in range(row):
        grid.append(list(map(int, input().split())))
    
    visited = [[False]*col for _ in range(row)]
    global area
    max_area = 0
    
    for i in range(row):
        for j in range(col):
            if grid[i][j] == 1 and not visited[i][j]:
                area = 1
                visited[i][j] = True
                dfs(grid, visited, j, i)
                max_area = max(area, max_area)
    print(max_area)
    
if __name__ == "__main__":
    main()
    
        